package com.zhuiyun.project.api.coachmanagement.controller;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.coachmanagement.entity.CoachManagement;
import com.zhuiyun.project.api.coachmanagement.mapper.CoachManagementMapper;
import com.zhuiyun.project.api.coachmanagement.model.CoachAddModel;
import com.zhuiyun.project.api.coachmanagement.model.CoachUpNameModel;
import com.zhuiyun.project.api.coachmanagement.model.CoachUpSexModel;
import com.zhuiyun.project.api.coachmanagement.service.CoachManagementService;
import com.zhuiyun.project.api.course.entity.Course;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.RestUtils;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.*;

/**
 * @ClassName CoachManagementController
 * @Description TODO
 * @Author wuwan
 * @Date 2023/11/2 13:40
 **/
@RestController
//@CrossOrigin
@RequestMapping("/CoachManagement")
@Api(tags = "教练信息")
public class CoachManagementController extends BaseController {
    @Autowired
    private CoachManagementService coachManagementService;

    @Resource
    private CoachManagementMapper coachManagementMapper;
    /*
    * @Author wuwan
    * @Description 添加教练信息
    * @Date 2023/11/2 13:53
    * @Return
    */
    @PostMapping("/addCoach")
    @ApiOperation(value = "添加教练信息")
    @OptLog(modular = "教练管理",type = CommonConstants.ADD,describe = "添加教练")
    public CommonResult addCoach(CoachAddModel coachAddModel, MultipartFile[] files) throws CommonException {
        return CommonResult.ok(coachManagementService.addCoach(coachAddModel,files));
    }
    /*
    * @Author wuwan
    * @Description 教练信息分页查询
    * @Date 2023/11/6 10:10
    * @Return
    */
    @GetMapping("/selectCoach")
    @ApiOperation(value = "教练信息分页查询")
    @OptLog(modular = "教练管理",type = CommonConstants.SELECT,describe = "教练信息分页查询")
    public CommonResult selectCoach(PageRequest pageRequest,String venueUniqueIdentifier,String coachName,String coachPhone){
        return CommonResult.ok(coachManagementService.selectCoach(pageRequest,venueUniqueIdentifier,coachName,coachPhone));
    }

    /*
    * @Author xy
    * @Description todo 学员教练信息查询
    * @Date 2023/11/23 10:33
    * 目前后端没有
    * @Return
    * @param
    */
    @GetMapping("/selectAllCoach")
    @ApiOperation(value = "学员教练信息查询")
    @OptLog(modular = "教练管理",type = CommonConstants.SELECT,describe = "学员教练信息查询")
    public CommonResult selectAllCoach(@RequestParam Integer coachId){
        // 根据前端传过来的coachId（教练id）来查询教练表id符合的数据
        QueryWrapper<CoachManagement> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",coachId);
        List<CoachManagement> coachManagements = coachManagementMapper.selectList(queryWrapper);
        return CommonResult.ok(coachManagements);
    }
    /*
    * @Author wuwan
    * @Description 修改教练信息
    * @Date 2023/11/9 8:45
    * @Return
    */
//    @GetMapping("/selectCoach")
//    @ApiOperation(value = "添加教练信息")
//    @OptLog(modular = "教练管理",type = CommonConstants.ADD,describe = "修改教练")

    /*
    * @Author wuwan
    * @Description 修改教练信息
    * @Date 2023/11/10 10:19
    * @Return com.zhuiyun.project.common.response.CommonResult
    */
    @PostMapping("/updVenue")
    @ApiOperation(value = "修改教练信息")
    @OptLog(modular = "教练管理",type = CommonConstants.UPDATE,describe = "修改教练")
    public CommonResult updVenue(CoachAddModel coachAddModel, MultipartFile[] files) throws CommonException {
        return CommonResult.ok(coachManagementService.updVenue(coachAddModel,files));
    }
    /*
     * @Author wuwan
     * @Description 根据邀请码查询教练id
     * @Date 2023/11/6 10:10
     * 目前后端没有
     * @Return
     */
    @GetMapping("/getCoachId")
    @ApiOperation(value = "根据邀请码查询教练id")
    @OptLog(modular = "教练管理",type = CommonConstants.SELECT,describe = "根据邀请码查询教练id")
    public CommonResult getCoachId(String coachCode){
        return CommonResult.ok(coachManagementService.getCoachId(coachCode));
    }

    /**
    * @Author wx
    * @Description 根据邀请码查询教练申请
    * @Date 2023/12/5 15:46
    * @Return
     * 目前后端没有
    * @param coachCode
    */
    @GetMapping("/selectCoachInfoByCode")
    @ApiOperation(value = "根据邀请码查询教练申请")
    @OptLog(modular = "教练管理",type = CommonConstants.SELECT,describe = "根据邀请码查询教练申请")
    public CommonResult selectCoachInfoByCode(String coachCode){
        return CommonResult.ok(coachManagementService.selectCoachInfoByCode(coachCode));
    }


    @DeleteMapping("/deletecoachImg")
    @ApiOperation(value = "删除教练图片")
    @OptLog(modular = "教练管理",type = CommonConstants.DELETE,describe = "删除教练图片")
    public CommonResult deletecoachImg(Integer id, Integer delImageId){
        return CommonResult.ok(coachManagementService.deletecoachImg(id,delImageId));
    }
}
